package cn.itcast.filter;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyPermsFilter extends AuthorizationFilter {
    public MyPermsFilter() {

    }

    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        Subject subject = this.getSubject(request, response);
        String[] perms = (String[]) ((String[]) mappedValue);
        //perms = ["部门管理","删除部门"]
        if (perms != null && perms.length > 0) {
            for (String s : perms) {
                if (subject.isPermitted(s)) {
                    return true;
                }
            }
            return false;
        }
        return true;
    }
}
